import Vue from "vue"
import Vuex from 'vuex'

Vue.use(Vuex)
// 创建一个store仓库
export default new Vuex.Store({
	state: {
		order: {},
		totalPrice: 0
	},
	mutations: {
		updateOrder(state, data) {
			state.order = data;
		},
		updatePrice(state, price) {
			state.totalPrice = price
		}
	},
	actions: {
		updateOrder(context, data) {
			context.commit("updateOrder", data);
		},
		updatePrice(context, price) {
			context.commit("updatePrice", price)
		}
	},
	getters: {
		getOrder(state) {
			return state.order ? state.order : {}
		},
		getTotalPrice(state) {
			return state.totalPrice > 0 ? state.totalPrice : 0
		}
	}
})